//
//  XS_InfoBottomAlertVC.swift
//  XueDao
//
//  Created by 韩云智 on 2020/12/21.
//

import UIKit

class XS_InfoBottomAlertVC: XS_BaseBottomAlertVC {
    lazy var text = "填写报名信息"
    lazy var name = getTextField("请输入您的名字")
    lazy var phone = XS_Singleton.shared.infoModel?.userBO.phone ?? ""
    lazy var beizhu = getTextField("请输入备注")
    
    override func upConfig() {
        super.upConfig()
        shouldEndEditing = true
        shouldClose = true
    }
    
    override func upView() {
        super.upView()
        customView = UIView(frame: CGRect(x: 0, y: .screenHeight, width: .screenWidth, height: .scale*330))
        view.addSubview(customView)
        let sLayer = CAShapeLayer()
        sLayer.fillColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
        sLayer.path = UIBezierPath(roundedRect: customView.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 20, height: 20) * .scale).cgPath
        customView.layer.addSublayer(sLayer)
        
        let label = UILabel.xsLabel(size: .scale*16, fontName: .medium, color: #colorLiteral(red: 0.2196078431, green: 0.2352941176, blue: 0.2470588235, alpha: 1), text: text)
        customView.addSubview(label)
        label.snp.makeConstraints {
            $0.left.equalTo(.scale*17)
            $0.top.equalTo(.scale*24)
        }
        
        let label1 = UILabel.xsLabel(size: .scale*14, fontName: .regular, color: #colorLiteral(red: 0.2196078431, green: 0.2352941176, blue: 0.2470588235, alpha: 1), text: "姓名")
        customView.addSubview(label1)
        label1.snp.makeConstraints({
            $0.left.equalTo(.scale*16)
            $0.top.equalTo(label.snp.bottom).offset(.scale*31)
        })
        let label2 = UILabel.xsLabel(size: .scale*14, fontName: .regular, color: #colorLiteral(red: 0.2196078431, green: 0.2352941176, blue: 0.2470588235, alpha: 1), text: "手机号码")
        customView.addSubview(label2)
        label2.snp.makeConstraints({
            $0.left.equalTo(.scale*16)
            $0.top.equalTo(label1.snp.bottom).offset(.scale*28)
        })
        let label3 = UILabel.xsLabel(size: .scale*14, fontName: .regular, color: #colorLiteral(red: 0.2196078431, green: 0.2352941176, blue: 0.2470588235, alpha: 1), text: "备注")
        customView.addSubview(label3)
        label3.snp.makeConstraints({
            $0.left.equalTo(.scale*16)
            $0.top.equalTo(label2.snp.bottom).offset(.scale*28)
        })
        let label4 = UILabel.xsLabel(size: .scale*12, fontName: .regular, color: #colorLiteral(red: 0.6666666667, green: 0.6941176471, blue: 0.7176470588, alpha: 1), text: "以上信息将用于主办方联系您")
        customView.addSubview(label4)
        label4.snp.makeConstraints({
            $0.left.equalTo(.scale*16)
            $0.top.equalTo(label3.snp.bottom).offset(.scale*21)
        })
        
        
        customView.addSubview(name)
        name.snp.makeConstraints({
            $0.height.equalTo(.scale*30)
            $0.left.equalTo(.scale*85)
            $0.right.lessThanOrEqualTo(-.scale*16)
            $0.centerY.equalTo(label1.snp.centerY)
        })
        let pLab = UILabel.xsLabel(size: .scale*14, fontName: .regular, color: #colorLiteral(red: 0.2196078431, green: 0.2352941176, blue: 0.2470588235, alpha: 1), text: phone.cipher(pre: 3, suf: 4))
        customView.addSubview(pLab)
        pLab.snp.makeConstraints({
            $0.left.equalTo(.scale*85)
            $0.centerY.equalTo(label2.snp.centerY)
        })
        customView.addSubview(beizhu)
        beizhu.snp.makeConstraints({
            $0.height.equalTo(.scale*30)
            $0.left.equalTo(.scale*85)
            $0.right.lessThanOrEqualTo(-.scale*16)
            $0.centerY.equalTo(label3.snp.centerY)
        })
        
        
        let sure = loadButton("完 成", color: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0), type: .sure)
        sure.layer.cornerRadius = .scale*20
        sure.layer.backgroundColor = #colorLiteral(red: 0.1647058824, green: 0.7411764706, blue: 0.6117647059, alpha: 1)
        customView.addSubview(sure)
        sure.snp.makeConstraints({
            $0.width.equalTo(.scale*343)
            $0.height.equalTo(.scale*40)
            $0.centerX.equalToSuperview()
            $0.bottom.equalTo(-.scale*39)
        })
    }

    func getTextField(_ hold: String) -> UITextField {
        let text = UITextField()
        text.font = .xsFont(name: .regular, .scale*14)
        text.textColor = #colorLiteral(red: 0.2196078431, green: 0.2352941176, blue: 0.2470588235, alpha: 1)
        text.returnKeyType = .done
        text.placeholder = hold
        text.rx.controlEvent(.editingDidEndOnExit)
            .subscribe()
            .disposed(by: disposeBag)
        return text
    }
}
